﻿<Window x:Class="CalendarSubscriptionApp.AppointmentsWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:CalendarSubscriptionApp="clr-namespace:CalendarSubscriptionApp"
    Title="AppointmentsWindow" Height="300" Width="500">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid Style="{StaticResource WindowGrid}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Label Grid.Row="0">Subscriptions:</Label>
        <Grid Grid.Row="1">
            <Grid.Style>
                <Style TargetType="{x:Type Grid}">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ViewModel.Subscriptions.Count}" Value="0" >
                            <Setter Property="Visibility" Value="Visible"  />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
            <Grid.RowDefinitions>
                <RowDefinition Height="2*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="3*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"  />
                <ColumnDefinition Width="Auto"  />
                <ColumnDefinition Width="10*"  />
                <ColumnDefinition Width="*"  />
            </Grid.ColumnDefinitions>
            <Image Source="Images/Favorites.png" Grid.Row="1" Grid.Column="1" />
            <TextBlock VerticalAlignment="Center" Grid.Row="1" Grid.Column="2" TextWrapping="Wrap">
                    <Run>No subscriptions active. To activate a subscription, enter the primary email address of the requested mailbox in the textbox below.</Run>
            </TextBlock>
        </Grid>
        <TabControl Grid.Row="1" ItemsSource="{Binding ViewModel.Subscriptions}" SelectedIndex="0">
            <TabControl.Style>
                <Style TargetType="{x:Type TabControl}">
                    <Setter Property="Visibility" Value="Visible" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ViewModel.Subscriptions.Count}" Value="0" >
                            <Setter Property="Visibility" Value="Collapsed"  />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TabControl.Style>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid Grid.IsSharedSizeScope="True">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition SharedSizeGroup="Subject" />
                                    <ColumnDefinition SharedSizeGroup="Start" />
                                    <ColumnDefinition SharedSizeGroup="End"/>
                                    <ColumnDefinition SharedSizeGroup="Duration"/>
                                </Grid.ColumnDefinitions>
                                <Label Grid.Column="0">Subject</Label>
                                <Label Grid.Column="1">Start</Label>
                                <Label Grid.Column="2">End</Label>
                                <Label Grid.Column="3">Duration</Label>
                            </Grid>
                            <ScrollViewer Grid.Row="1">
                                <ItemsControl ItemsSource="{Binding Appointments}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition SharedSizeGroup="Subject" />
                                                    <ColumnDefinition SharedSizeGroup="Start" />
                                                    <ColumnDefinition SharedSizeGroup="End"/>
                                                    <ColumnDefinition SharedSizeGroup="Duration"/>
                                                </Grid.ColumnDefinitions>
                                                <Label Grid.Column="0" Content="{Binding Subject}" />
                                                <Label Grid.Column="1" Content="{Binding Start}" />
                                                <Label Grid.Column="2" Content="{Binding End}" />
                                                <Label Grid.Column="3" Content="{Binding Duration}" />
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ScrollViewer>
                            <Grid.Style>
                                <Style TargetType="{x:Type Grid}">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Status}" Value="Ok">
                                            <Setter Property="Visibility" Value="Visible" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Grid.Style>
                        </Grid>

                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"  />
                                <ColumnDefinition Width="Auto"  />
                                <ColumnDefinition Width="*"  />
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1">
                                <Image Source="Images/error.png" />
                                <Label Content="{Binding ErrorMessage}" VerticalAlignment="Center" />
                            </StackPanel>

                            <Grid.Style>
                                <Style TargetType="{x:Type Grid}">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Status}" Value="Error">
                                            <Setter Property="Visibility" Value="Visible" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Grid.Style>
                        </Grid>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"  />
                                <ColumnDefinition Width="Auto"  />
                                <ColumnDefinition Width="*"  />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Row="1" Grid.Column="1">
                                <Label Content="Loading..." HorizontalAlignment="Center"  />
                                <ProgressBar IsIndeterminate="true" Width="150" Height="12" />
                            </StackPanel>
                            <Grid.Style>
                                <Style TargetType="{x:Type Grid}">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Status}" Value="Loading">
                                            <Setter Property="Visibility" Value="Visible" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Grid.Style>
                        </Grid>
                    </Grid>
                </DataTemplate>
            </TabControl.ContentTemplate>
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Label Content="{Binding MailboxId}" />
                        <Button Grid.Column="1" Style="{StaticResource TabCloseButton}" Command="CalendarSubscriptionApp:CustomCommands.CloseTab" CommandParameter="{Binding}" />
                    </Grid>
                </DataTemplate>
            </TabControl.ItemTemplate>
        </TabControl>
        <StackPanel Orientation="Horizontal" Grid.Row="2" Margin="4" Style="{StaticResource DefaultStackPanel}">
            <TextBlock>
				<Run Text="Open anothers users mailbox:" />
            </TextBlock>
            <TextBox Text="{Binding NewMailboxAddress}" Width="150" />
            <Button Content="Open calendar" Click="OpenMailboxButtonClick"  Width="120"/>
        </StackPanel>
    </Grid>
</Window>
